package com.example.xgakj.mylibrary.mvp.utils;

import android.content.Context;
import android.telephony.TelephonyManager;

public class CellphoneInfo {
	
	private static TelephonyManager mTelephonyManager;
	private static String mDeviceId;
	public static TelephonyManager getTelephonyManager(Context context) {  
	    // 获取telephony系统服务，用于取得SIM卡和网络相关信息  
	    if (mTelephonyManager == null) {  
	        mTelephonyManager = (TelephonyManager) context  
	                .getSystemService(Context.TELEPHONY_SERVICE);  
	    }
	    return mTelephonyManager;  
	}  
	  
	/**  
	 * 唯一的设备ID： GSM手机的 IMEI 和 CDMA手机的 MEID. Return null if device ID is not  
	 * 取得手机IMEI  
	 * available.  
	 */  
	public static String getDeviceId(Context context) {  
	    mDeviceId = getTelephonyManager(context).getDeviceId();// String
		if (mDeviceId==null){
			return "";
		}
		if (mDeviceId.length()>15){
			mDeviceId=mDeviceId.substring(0,15);
		}else if (mDeviceId.length()<15){
			int count=15-mDeviceId.length();
			for (int i = 0; i <count ; i++) {
				mDeviceId="0"+mDeviceId;
			}
		}
	    return mDeviceId;  
	}  
	  
	

}
